package com.haiqu.haiqu_helper.service.serviceImpl;

import com.haiqu.haiqu_helper.GlobalConstant;
import com.haiqu.haiqu_helper.dao.AppInfoBeanRepo;
import com.haiqu.haiqu_helper.dao.LicenseBeanRepo;
import com.haiqu.haiqu_helper.model.JsonResult;
import com.haiqu.haiqu_helper.model.resultModel.GetAppListOut;
import com.haiqu.haiqu_helper.model.table.AppInfoBean;
import com.haiqu.haiqu_helper.model.table.LicenseBean;
import com.haiqu.haiqu_helper.service.AppService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * className: AppServiceImpl
 * description: TODO
 * author: mj
 * date: 2019/9/197:28 PM
 **/
@Service
public class AppServiceImpl implements AppService {
	@Autowired
	AppInfoBeanRepo appInfoBeanRepo;
	@Override
	public JsonResult getAppList() {
		JsonResult jsonResult = new JsonResult();
		AppInfoBean bean = new AppInfoBean();
		bean.setFenable(GlobalConstant.APP_STATUS.ON);
		Example<AppInfoBean> example = Example.of(bean);
		Sort sort = new Sort(Sort.Direction.DESC,"fappnum");
		List<AppInfoBean> appInfoBeans = appInfoBeanRepo.findAll(example,sort);
		List<GetAppListOut> outs = new ArrayList<>();
		for (AppInfoBean infoBean :appInfoBeans){
			GetAppListOut out = new GetAppListOut();
			out.setAppname(infoBean.getFappname());
			out.setAppnum(infoBean.getFappnum());
			out.setMachine(infoBean.getFmachine());
			out.setEnable(infoBean.getFenable()==GlobalConstant.APP_STATUS.ON?true:false);
			outs.add(out);
		}
		jsonResult.setResult(outs);
		return jsonResult;
	}
}
